#include "BlockQueue.hpp"
#include <time.h>
#include <cstdlib>

using namespace NSBlockQueue;

void *ConsumerRun(void *args)
{
    BlockQueue<int> *bq = (BlockQueue<int> *)args;
    int data;
    while (true)
    {
        bq->Pop(&data);
        std::cout << "消费者消费了一个数据: " <<  data << std::endl;
    }
}

void *ProducerRun(void *args)
{
    BlockQueue<int> *bq = (BlockQueue<int> *)args;
    while (true)
    {
        int data = rand() % 20;
        std::cout << "生产者生成了一个数据：" << data << std::endl;
        bq->Push(data);
        sleep(1);
    }
}

int main()
{
    srand((unsigned)time(nullptr));
    BlockQueue<int> *bq = new BlockQueue<int>();

    pthread_t consumer, prodecer;
    pthread_create(&consumer, nullptr, ConsumerRun, (void *)bq);
    pthread_create(&prodecer, nullptr, ProducerRun, (void *)bq);

    pthread_join(consumer, nullptr);
    pthread_join(prodecer, nullptr);
    return 0;
}